<template>
	<view>
		<u-sticky>
			<view class="tabs">
				<view class="title1">
					<view>
						达人售卖收益比例为
					</view>
					<view>
						{{percent}}%
					</view>
				</view>
				<view class="title2">
					单项比例不可超过达人售卖返佣比例，为0不返佣
				</view>
			</view>
		</u-sticky>
		<view class="content">
			<view class="list" v-for="item,index in levelList" :key="index">
				<view class="title">
					V{{item.grade}}等级
					<u-input type="digit" inputAlign="right" border="none" v-model="model['vip'+item.grade]" placeholder="请输入"></u-input>
					<span class="unit">%</span>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="btn" @click="save">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				levelList:[],
				model:{},
				percent:null
			};
		},
		onLoad(e) {
			this.percent = e.percent
			this.rq.getData('common/level').then(res=>{
				this.levelList = res.data
			})
		},
		onShow(){
			uni.$on('model',(data)=>{
				this.model = data?data:{}
			})
		},
		onUnload(){
			uni.$off('model')
		},
		methods: {
			save() {
				let bool = true
				Object.keys(this.model).map(key=>{
					if(this.model[key]*1 > this.percent*1){
						uni.showToast({
							title:`单项比例不可超过达人售卖返佣比例`,
							icon:'none'
						})
						bool = false
					}
				})
				if(!bool) return
				const pages = getCurrentPages();
				const prevPage = pages[pages.length - 2];
				
				uni.navigateBack({
					success: () => {
						prevPage.$vm.receiveGrade(this.model);
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.content {
		margin-top: 20rpx;
		width: 100%;
		padding-bottom: 120rpx;

		.text {
			font-family: PingFang SC;
			font-size: 12px;
			font-weight: normal;
			line-height: 14px;
			letter-spacing: 0px;
			color: #FF7681;
			margin: 20rpx 40rpx;
		}

		.list {
			width: 94%;
			margin: 20rpx auto;
			border-radius: 8px;
			opacity: 1;
			background: #FFFFFF;

			.title {
				font-family: PingFang SC;
				font-size: 14px;
				font-weight: normal;
				line-height: 15px;
				letter-spacing: 0px;
				color: #333333;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx;

				.unit {
					margin-left: 20rpx;
				}
			}

			.con1 {
				font-family: PingFang SC;
				font-size: 12px;
				font-weight: normal;
				line-height: 14px;
				letter-spacing: 0px;
				color: #999999;
				text-align: end;
				padding: 30rpx;
			}

			.con2 {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				font-family: PingFang SC;
				font-size: 12px;
				font-weight: normal;
				line-height: 14px;
				letter-spacing: 0px;
				color: #FF7681;
				padding: 30rpx;
			}
		}
	}

	.tabs {
		width: 100%;
		height: 116rpx;
		background: #FEF4F5;
		padding: 20rpx 0;

		.title1 {
			font-family: PingFang SC;
			font-size: 14px;
			font-weight: normal;
			line-height: 28px;
			text-align: center;
			letter-spacing: 0px;
			color: #FF7681;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;
		}

		.title2 {
			font-family: PingFang SC;
			font-size: 10px;
			font-weight: normal;
			line-height: 28px;
			letter-spacing: 0px;
			color: #FF7681;
			padding: 0 20rpx;
		}
	}

	.bottom {
		position: fixed;
		bottom: 0px;
		width: 100%;
		height: 59px;
		opacity: 1;
		background: #FFFFFF;
		box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.1);

		.btn {
			margin: 20rpx auto;
			width: 335px;
			height: 74rpx;
			border-radius: 102px;
			opacity: 1;

			background: #FF5866;

			border: 1px solid #FF5866;
			font-family: PingFang SC;
			font-size: 15px;
			font-weight: normal;
			line-height: 15px;
			letter-spacing: 0px;

			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			letter-spacing: 10rpx;
		}
	}
</style>